﻿// test_string.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "Plugins/stringHelper/cStringHelper.h"
#include "Plugins/plateHelper/cPlateHelper.h"

#include <memory.h>
#include <vector>

using namespace libtool_sdk;
using namespace libtool_sdk::Helper;

void test_string()
{
	const char* str = "Hello World!";
	std::cout << str << std::endl;

	char chBuffer[256] = { 0 };
	const char* pToReplace = "l";
	const char* pNewChar = "L";
	bool bRet = Tool_ReplaceStringInStd(str, pToReplace, pNewChar, chBuffer, sizeof(chBuffer));
	printf("Tool_ReplaceStringInStd(%s,%s,%s) = %d, final string = %s \n", str, pToReplace, pNewChar, bRet, chBuffer);

	const char* pTargetCharSequence = "123,f6-7";
	const char* pRegularExpression = "^\\d+,[a-zA-Z]\\d-\\d$";
	bRet = Tool_CheckIfMatchExpressions(pTargetCharSequence, pRegularExpression);
	printf("Tool_checkIfMatchExpressions(%s,%s) = %d \n", pTargetCharSequence, pRegularExpression, bRet);

	char chDestBuf[256] = { 0 };
	const char* pSrcStr = "1234567";
	int iRet = Tool_CopyStringToBuffer(chDestBuf, sizeof(chDestBuf), pSrcStr);
	printf("Tool_CopyStringToBuffer(%s,%d,%s) = %d, final string = [%s] \n", chDestBuf, sizeof(chDestBuf), pSrcStr, iRet, chDestBuf);

	const char* pXmlInfo = "<root><item  value=\"123\">teststring</item></root>";
	const char* pstrItemName = "item";
	const char* pstrAttributeName = "value";
	char chValueBuf[256] = { 0 };
	int iBufLen = sizeof(chValueBuf);

	bRet = Tool_GetDataAttributFromAppenedInfo(
		pXmlInfo,
		pstrItemName,
		pstrAttributeName,
		chValueBuf,
		&iBufLen);
	printf("Tool_GetDataAttributFromAppenedInfo(%s,%s,%s) = %d, final string = [%s] \n",
		pXmlInfo, pstrItemName, pstrAttributeName, bRet, chValueBuf);

	memset(chValueBuf, 0, sizeof(chValueBuf));
	bRet = Tool_GetTextNodeFromXML(pXmlInfo, pstrItemName, chValueBuf, sizeof(chValueBuf));
	printf("Tool_GetTextNodeFromXML(%s,%s) = %d, final string = [%s] \n", pXmlInfo, pstrItemName, bRet, chValueBuf);

	const char* pTextWithSpace = "  123   456   ";
	char chFinalString[256] = { 0 };
	bRet = Tool_remove_consecutive_spaces(pTextWithSpace, chFinalString, sizeof(chFinalString));
	printf("Tool_remove_consecutive_spaces(%s) = %d, final string = [%s] \n", pTextWithSpace, bRet, chFinalString);

	memset(chFinalString, 0, sizeof(chFinalString));
	bRet = Tool_Trim(pTextWithSpace, chFinalString, sizeof(chFinalString));
	printf("Tool_trim(%s) = %d, final string = [%s] \n", pTextWithSpace, bRet, chFinalString);

	memset(chFinalString, 0, sizeof(chFinalString));
	char chData[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11 };
	bRet = Tool_ByteToString(chData, sizeof(chData), chFinalString, sizeof(chFinalString));
	printf("Tool_ByteToString(%d) = %d, final string = [%s] \n", sizeof(chData), bRet, chFinalString);
}

void test_plate()
{
	const char* chSrcPlate = "绿贵A12345D";
	const char* chDestPlate = "蓝贵A12345";
	char chBuf[256] = { 0 };
	bool bRet =  Tool_FindMaxSameSubString(chSrcPlate, chDestPlate, chBuf, sizeof(chBuf));
	printf("Tool_FindMaxSameSubString(%s,%s) = %d, final string = [%s] \n", chSrcPlate, chDestPlate, bRet, chBuf);

	bRet = Tool_DimCompare(chSrcPlate, chDestPlate);
    printf("Tool_DimCompare(%s,%s) = %d \n", chSrcPlate, chDestPlate, bRet);

	int iIfPureElectric = 0;
	int iIfLargeCar = 0;
	bRet = Tool_Analysis_new_energy_vehicles_plate_info_normal(chSrcPlate, &iIfPureElectric, &iIfLargeCar);
    printf("Tool_analysis_new_energy_vehicles_plate_info_normal(%s) = %d, iIfPureElectric = %d, iIfLargeCar = %d \n",
		chSrcPlate, bRet, iIfPureElectric, iIfLargeCar);

	int iRet = Tool_AnalysisPlateColorNo(chSrcPlate);
    printf("Tool_AnalysisPlateColorNo(%s) = %d \n", chSrcPlate, iRet);

	char chColorBuf[256] = { 0 };
	char chPlateBuf[256] = { 0 };
	bRet = Tool_ProcessPlateNo(chSrcPlate, chPlateBuf, sizeof(chPlateBuf), chColorBuf, sizeof(chColorBuf));
    printf("Tool_ProcessPlateNo(%s) = %d, chPlateBuf = [%s], chColorBuf = [%s] \n", chSrcPlate, bRet, chPlateBuf, chColorBuf);

	memset(chPlateBuf, 0, sizeof(chPlateBuf));
	memset(chColorBuf, 0, sizeof(chColorBuf));
	int iColorCode = 0;
	bRet = Tool_SeparatePlateNumbersAndColor(chSrcPlate, chPlateBuf, chColorBuf, &iColorCode);
	printf("Tool_SeparatePlateNumbersAndColor(%s) = %d, chPlateBuf = [%s], chColorBuf = [%s], iColorCode = %d \n",
		chSrcPlate, bRet, chPlateBuf, chColorBuf, iColorCode);

	std::vector<int> vec{1,2,22,12,222};
	for (auto it = vec.begin(); it != vec.end(); ++it)
	{
		int iValue = *it;
		int iType =  Tool_GetAlexType(iValue);
        printf("Tool_GetAlexType(%d) = %d \n", iValue, iType);
	}

	const char* pAxleType = "1+2+222";
	int iGroupCount = Tool_GetAlexGroupCount(pAxleType);
	iRet = Tool_AnalysisVelchAxleType(pAxleType, iGroupCount);
	printf("Tool_AnalysisVelchAxleType(%s, %d) = %d \n", pAxleType, iGroupCount, iRet);

	const char* pVehType = "货2";
	iRet = Tool_AnalysisVelchType(pVehType);
    printf("Tool_AnalysisVelchType(%s) = %d \n", pVehType, iRet);
}


int main()
{
	test_string();
	test_plate();
	return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
